package avicit.bdp.dgs.mdm.rest;

import avicit.bdp.dgs.mdm.dto.ColumnDTO;
import avicit.bdp.dgs.mdm.service.ColumnService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-12-05
 * @类说明：ColumnRest
 * @修改记录：
 * @注意事项：
 * @主要功能：字段Rest接口
 */
@RestController
@Api(tags = "mdm", description = "字段Rest接口")
@RequestMapping("/api/bdp/dgs/mdm/column")
public class ColumnRest {
    @Autowired
    private ColumnService columnService;

//    /**
//     * 新增字段
//     *
//     * @param columnDTO
//     * @return
//     */
//    @PostMapping("/add")
//    @ApiOperation(value = "新增字段")
//    public ResponseMsg<String> addColumn(@RequestBody ColumnDTO columnDTO) {
//        ResponseMsg<String> responseMsg = new ResponseMsg<>();
//
//        responseMsg.setResponseBody(this.columnService.addColumn(columnDTO));
//
//        return responseMsg;
//    }

    /**
     * 批量新增字段
     *
     * @param columnList
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增字段")
    public ResponseMsg<Boolean> saveColumn(@RequestBody List<ColumnDTO> columnList) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.columnService.saveColumn(columnList));

        return responseMsg;
    }

    /**
     * 删除/批量删除字段，多个id使用英文逗号隔开
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除/批量删除字段 ，多个id使用英文逗号隔开")
    public ResponseMsg<Integer> deleteColumn(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.columnService.deleteColumn(id));

        return responseMsg;
    }

    /**
     * 修改字段
     *
     * @param columnDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改字段")
    public ResponseMsg<Boolean> updateColumn(@RequestBody ColumnDTO columnDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.columnService.updateColumn(columnDTO));

        return responseMsg;
    }

    /**
     * 查询模型中字段列表
     *
     * @param tableId 模型ID
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询模型详情")
    public ResponseMsg<List<ColumnDTO>> getColumnList(@ApiParam(value = "tableId", name = "tableId") @RequestParam String tableId) {
        ResponseMsg<List<ColumnDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.columnService.getColumnList(tableId));

        return responseMsg;
    }
}
